#user who posted this
user = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.title
Testing your App
When you run your app now, it should return a list of todos (fig. 3):
Figure 3
Checking If a User is Logged In
Now we should only display todos if a user is logged in. To do so, in return, add:
Modify Bold Code
…
import Container from 'react-bootstrap/Container';
import Button from 'react-bootstrap/Button';
import Alert from 'react-bootstrap/Alert';[DCB9][JL10]
const TodosList = props => {
…
return (
<Container>
{props.token == null || props.token === "" ? (
<Alert variant='warning'>
You are not logged in. Please <Link to={"/login"}>login</Link> to see your todos.
</Alert>
) : (
<div>
{todos.map((todo) => {
…
})}
</div>
)}
</Container>
);
}
export default TodosList;
If the user is logged in, i.e. props.token will contain a value and only then do we proceed to list the todos. Else, the
user is not logged in and we log an alert warning message “You are not logged in.” and display the login link (fig.
4).